package com.exc.rabbitmqboot;


import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableRabbit
@Configuration
public class RabbitConfig {


    @Bean
    public Queue myQueue(){
        return new Queue("myQueue");
    }

    @Bean
    public Exchange myExchange() {
//        主体交换机
//        return new TopicExchange("topic.biz.ex", false, false, null);
//        直接交换机
        return new DirectExchange("myExchange", false, false, null);
//        分散交换机
//        return new FanoutExchange("fanout.biz.ex", false, false, null);
//        头信息交换机
//        return  new HeadersExchange("headers.biz.ex", false, false, null);
//        自定义交换机
//        return new CustomExchange("myExchange", ExchangeTypes.DIRECT, false, false, null);
    }

    @Bean
    public Binding myBinding() {
        // 绑定目的地： 绑定类型，是到交换机还是到队列，交换机名称、路由key、绑定属性
//        return new Binding("exchangeBinding", Binding.DestinationType.EXCHANGE, "myExchange", "custom.biz.ex", null);

        // 绑定了交换机direct.bix.ex 到 队列 myQueue，路由key是direct.biz.ex
        return new Binding("myQueue", Binding.DestinationType.QUEUE, "myExchange", "direct.biz.ex", null);
    }

}
